<?php
use common\models\Article;
?>
<?php $this->beginBlock('title'); ?><?=$model['game']['game_name'];?>新闻资讯,<?=$model['game']['game_name'];?>_二狐游戏<?php $this->endBlock();?>
<?php $this->beginBlock('keywords'); ?><?=$model['game']['game_name'];?>,<?=$model['game']['game_name'];?>新闻（活动）,<?=$model['game']['game_name'];?>下载<?php $this->endBlock();?>
<?php $this->beginBlock('description'); ?><?=$model['game']['game_name'];?>新闻资讯为您提供最热游戏新闻,<?=$model['game']['game_name'];?>开服公告,<?=$model['game']['game_name'];?>下载<?php $this->endBlock();?>
<div class="me_shadow public new_public">
      <div class="hot_game">
        <ul>
            <li><a href="<?=Yii::$app->urlManager->createUrl(['game/detail','version_id'=>$model['id']]);?>">
               <p class="p1"><img src="<?=filepath($model['game']['game_logo']);?>" class="myimg"></p>
               <p class="p2">
                  <span class="span1"><?=$model['game']['game_name'];?></span>
                  <span class="span2"><?=$model['version_size']?>MB <br><i>
                  <?php foreach($types as $type):?>
                  <?=$type['type_name'].' ';?>
                  <?php endforeach;?>
                  </i>下载：<em><?=$model['game']['game_downclick']?></em></span>
               </p>
               <p class="p3"><span>下载</span></p>
            </a></li>
        </ul>
     </div>
</div>

<div class="me_shadow public womargin">
    <div class="local"><a href="<?=Yii::$app->urlManager->createUrl(['game/detail','version_id'=>$model['id']]);?>"><?=$model['game']['game_name'];?></a><?php if($kind==Article::KIND_NEWS){echo '新闻';}elseif($kind==Article::KIND_ACTIVITY){echo '活动';}else{echo '未知';}?></div>
    <div class="collect_list">
        <ul class="me_shadow" id="article_list">
                 <?php foreach($articles as $article):?>
                <li><a href="<?=Yii::$app->urlManager->createUrl(['/article/detail','id'=>$article['id']]);?>">
                   <p class="p1"><img src="<?=filepath($article['logo_path']);?>"></p>
                   <p class="p2">
                      <span class="span1"><?=truncate($article['title'],25);?></span>
                      <span class="span2"><?=date('Y-m-d',$article['created_at']);?></span>
                   </p>
                </a></li>
                <?php endforeach;?>
        </ul>
    </div>
</div>
<?php if($limit<=count($articles)):?>
<div class="loadgame" data-page="2"><p>加载更多资讯 </p></div>
<?php endif;?>

<?php $this->beginBlock('script'); ?>
<script type="text/javascript">
//点击加载更多时，瀑布流实现
$(".loadgame").click(function() {
    getArticles();
});

//将时间戳转化为2015-09-09这样格式的日期 by jois add at 20150911
function formatDate(date){
	date=new Date(parseInt(date)*1000).toLocaleDateString();
	return date.replace(/\//g, '-').replace(/-(\d)?/, "-0$1");;
}

//加载更多函数
function getArticles(){
	//初始化参数
	var add = $(".loadgame");
	var page = parseInt(add.attr('data-page'));
	if (isNaN(page) || page < 2) {
        page = 2;
    }

    //防止恶意点击
	if (add.attr('data-action') == 1) {
        return false;
    }
	add.attr('data-action', 1);
    add.find('p').text('获取中...');

    //ajax请求数据
    $.ajax({
        type: 'GET',
        url: "<?=Yii::$app->urlManager->createUrl('/article/ajax-list')?>",
        data: { page: page },
        dataType: 'json',
        success: function(data) {
            if (data.length < 1) {
                add.hide();
            } else {
                var html = "";
                var file_path1="<?=\Yii::$app->params['filePath'];?>";
                var file_path2="<?=\Yii::$app->params['pipawImgPath'];?>";
                var tmp="<?=Yii::$app->urlManager->createUrl('/article/detail');?>";
                for (var i in data) {
                    if(data[i]['logo_path'].substr(1,1)=='/'){
                    	var img_path=file_path1+data[i]['logo_path'];
                    }else{
                    	var img_path=file_path2+data[i]['logo_path'];
                    }
                    html+='<li><a href="'+tmp+'?id='+data[i]['id']+'"><p class="p1"><img src="'+img_path+'"></p>' +
                	'<p class="p2"><span class="span1">'+data[i]['title']+'</span><span class="span2">'+formatDate(data[i]['created_at'])+
                	'</span></p></a></li>';
                }
                $("#article_list").append(html);
                add.attr('data-page', parseInt(add.attr('data-page'))+1);
            }
            add.attr('data-action', 0);
            add.find('p').text('加载更多游戏');
        },
        error: function(xhq) {
        	alert(xhq.responseText);
            add.attr('data-action', 0);
            add.find('p').text('加载更多游戏');
        }
    });
}
</script>
<?php $this->endBlock();?>
